function pigIt(str) {
    return str.split(" ").map(x=>{
        let tmp = x.substring(1)+x.substring(0,1)
        return tmp.match(/[a-zA-Z]/g)!=null?tmp+'ay':tmp
    }).join(" ")
}
console.log(pigIt("Pig latin is cool !"));